#include <iostream>
#include <string>

using namespace std;

const int N = 310;
int f[N][N];

int main()
{
    string a, b;
    cin >> a;
    cin >> b;
    string tmp;
    if (a.size() > b.size())
    {
        a.swap(b);
    }
    int len = 0, end = 0;
    for (int i = 1; i <= a.size(); ++i)
    {
        for (int j = 1; j <= b.size(); ++j)
        {
            if (a[i - 1] == b[j - 1])
            {
                f[i][j] = f[i - 1][j - 1] + 1;
            }
            else
            {
                f[i][j] = 0;
            }
            if (f[i][j] > len)
            {
                end = i - 1;
                len = f[i][j];
            }
        }
    }

    cout << a.substr(end - len + 1, len);
    return 0;
}